import {
    ChangePwdForm,
    CreateUserForm,
    LoginFormType,
    UserDisableForm, UserEditAdminForm, UserEditForm,
    UserQueryParams,
    UserType
} from "@/api/user/types";
import http from "@/utils/http";
import {ListResponse} from "@/types";

/**
 * 用户登录
 * @param params
 */
export const loginApi = async (params: LoginFormType)=>{
    const res = await http.post<string>("/v1/user/login", params)
    return res.data
}

/**
 * 个人信息
 */
export const ownInfoApi = async ()=>{
    const res = await http.get<UserType>("/v1/user/ownInfo", {})
    return res.data.data
}

/**
 * 用户列表
 * @param params
 */
export const userListApi = async (params: UserQueryParams)=>{
    const res = await http.get<ListResponse<UserType>>("/v1/user", params)
    return res.data
}

/**
 * 用户详情
 * @param id
 */
export const userDetailApi = async (id: number)=>{
    const res = await http.get<UserType>(`/v1/user/${id}`, {})
    return res.data
}

/**
 * 用户启用、禁用
 * @param params
 */
export const userDisableApi = async (params: UserDisableForm)=>{
    const res = await http.patch(`/v1/user/disable`, params)
    return res.data
}

/**
 * 用户修改密码
 * @param params
 */
export const userChangPwdApi = async (params: ChangePwdForm)=>{
    const res = await http.patch(`/v1/user/changePwd`, params)
    return res.data
}

/**
 * 修改用户信息
 * @param params
 */
export const userEditApi = async (params: UserEditForm)=>{
    const res = await http.patch(`/v1/user`, params)
    return res.data
}

/**
 * 删除用户
 * @param id
 */
export const userDeleteApi = async (id: number)=>{
    const res = await http.delete(`/v1/user/${id}`, {})
    return res.data
}

/**
 * 创建用户
 * @param params
 */
export const userCreateApi = async (params: CreateUserForm)=>{
    const res = await http.post(`/v1/user`, params)
    return res.data
}

/**
 * 管理员修改用户信息
 * @param params
 */
export const userEditAdminApi = async (params: UserEditAdminForm)=>{
    const res = await http.patch(`/v1/user/admin`, params)
    return res.data
}